/*(C) Copyright

    This file is part of GastosMovil.
    
    GastosMovil is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    GastosMovil is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with GastosMovil.  If not, see <http://www.gnu.org/licenses/>.
    
    Autor: Antonio Cristóbal Álvarez Abellán -> acabellan@gmail.com
    
    */

package deeloco.android.gastos.Movil.plus;


import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;

public class widgetProvider1x1 extends AppWidgetProvider {
	

	Context contexto;
	static final String PREFERENCIAS_WIDGET="MIS_PREFERENCIAS_WIDGET";
	static final String PREF_NUMERO="NUMERO_ULTIMA";
	
	//private SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy  hh:mm:ss a");
	String strWidgetText = "";
	//public static String MY_WIDGET_UPDATE = "MY_OWN_WIDGET_UPDATE";

	@Override
	public void onDeleted(Context context, int[] appWidgetIds) {
		// TODO Auto-generated method stub
		//super.onDeleted(context, appWidgetIds);
	}

	@Override
	public void onDisabled(Context context) {
		// TODO Auto-generated method stub
        //super.onDisabled(context);
	}

	@Override
	public void onEnabled(Context context) {
		// TODO Auto-generated method stub
		//super.onEnabled(context);
		//Toast.makeText(context, "onEnabled()", Toast.LENGTH_LONG).show();
	}

	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
		// TODO Auto-generated method stub
		Log.d("widgetProvider.java", "EJECUTANDOSE onUpdate");
		contexto=context;
		actualizarWidget aw= new actualizarWidget(context,R.layout.widget1x1);
		RemoteViews updateView = aw.buildUpdate(false);
	    appWidgetManager.updateAppWidget(appWidgetIds, updateView);
	}

	/* (non-Javadoc)
	 * @see android.appwidget.AppWidgetProvider#onReceive(android.content.Context, android.content.Intent)
	 */
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		super.onReceive(context, intent);
		
		Log.d("RELOG", "intent.getAction="+intent.getAction());
		
		//if("android.appwidget.action.APPWIDGET_UPDATE".equals(intent.getAction()))
		//	return;
		
		if("android.appwidget.action.APPWIDGET_UPDATE".equals(intent.getAction())||"ACTUALIZAR_WIDGET".equals(intent.getAction()))	
		{
				Log.d("RELOG", "EJECUTANDOSE onReceive widget1x1");
			   AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
			   ComponentName thisAppWidget = new ComponentName(context.getPackageName(), widgetProvider1x1.class.getName());
			   int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

			   //onUpdate(context, appWidgetManager, appWidgetIds);
			   
				contexto=context;
				actualizarWidget aw= new actualizarWidget(context,R.layout.widget1x1);
				RemoteViews updateView = aw.buildUpdate();
			    appWidgetManager.updateAppWidget(appWidgetIds, updateView);
			    Log.d("RELOG", "onReceive FIN UPDATE");

			   
		}
	}
	
	
	
	
}
